package com.qiezikaka.kaka.ui;

import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.qiezikaka.kaka.base.AppStatusConstant;
import com.qiezikaka.kaka.base.AppStatusManager;
import com.qiezikaka.kaka.databinding.ActivitySplashBinding;
import com.qiezikaka.kaka.net.DataManager;
import com.qiezikaka.kaka.ui.single.StyleSingleActivity;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;

import java.util.Timer;
import java.util.TimerTask;

/**
 * 闪屏页
 */
public class SplashActivity extends AppCompatActivity{

    private com.qiezikaka.kaka.databinding.ActivitySplashBinding splashBinding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        QMUIStatusBarHelper.translucent(this);
        QMUIStatusBarHelper.setStatusBarLightMode(this);
        splashBinding = ActivitySplashBinding.inflate(getLayoutInflater());
        setContentView(splashBinding.getRoot());

        // 此处是解决开机自启动的问题
        //检查是否已经授予权限，大于6.0的系统适用，小于6.0系统默认打开，无需理会
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) {
//            //没有权限，须要申请权限，由于是打开一个受权页面，因此拿不到返回状态的，因此建议是在onResume方法中重新执行一次校验
//            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
//            intent.setData(Uri.parse("package:" + getPackageName()));
//            startActivity(intent);
//        }

        initdata();
    }

    private void initdata() {
        AppStatusManager.getInstance().setAppStatus(AppStatusConstant.APP_NORMAL);
        DataManager.getInstance().initService();
        setTimer();
    }

    private void setTimer() {
        Timer timer = new Timer();
        TimerTask tast = new TimerTask() {
            @Override
            public void run() {
                Intent mMainIntent = new Intent(SplashActivity.this, StyleChoiceAllActivity.class);
//                Intent mMainIntent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(mMainIntent);

                finish();
            }
        };
        timer.schedule(tast, 500);//10秒后
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
